/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Pressão.java
 *
 * Created on 26/10/2011, 13:25:57
 */

package br.com.fatecpg.tp1.formularios;

/**
 *
 * @author Fatec
 */
public class Pressão extends javax.swing.JInternalFrame {

    /** Creates new form Pressão */
    public Pressão() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        emjLabel = new javax.swing.JLabel();
        MetrodeaguajLabel = new javax.swing.JLabel();
        BarjLabel = new javax.swing.JLabel();
        HectopascaljLabel = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        KilopascaljLabel = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        PascaljLabel = new javax.swing.JLabel();
        MilibarjLabel = new javax.swing.JLabel();
        KilopascaljTextField1 = new javax.swing.JTextField();
        HectopascaljTextField1 = new javax.swing.JTextField();
        BarjTextField = new javax.swing.JTextField();
        MilibarjTextField = new javax.swing.JTextField();
        PascaljTextField = new javax.swing.JTextField();
        MetrodeaguajTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(0, 102, 102));
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Conversão de PRESSÃO  ( Luiz Fernando e Renata )");

        jLabel1.setText("Converter:");

        emjLabel.setText("em:");

        MetrodeaguajLabel.setText("Metro de água");

        BarjLabel.setText("Bar");

        HectopascaljLabel.setText("Hectopascal");

        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });

        KilopascaljLabel.setText("Kilopascal");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kilopascal", "Hectopascal", "Bar", "Milibar", "Pascal", "Metro de água" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });

        PascaljLabel.setText("Pascal");

        MilibarjLabel.setText("Milibar");

        KilopascaljTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KilopascaljTextField1ActionPerformed(evt);
            }
        });

        HectopascaljTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HectopascaljTextField1ActionPerformed(evt);
            }
        });

        BarjTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BarjTextFieldActionPerformed(evt);
            }
        });

        MilibarjTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MilibarjTextFieldActionPerformed(evt);
            }
        });

        PascaljTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PascaljTextFieldActionPerformed(evt);
            }
        });

        MetrodeaguajTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MetrodeaguajTextFieldActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/fatecpg/tp1/imagens/rodape2.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jTextField2)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(79, 79, 79)
                                .addComponent(emjLabel))
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(PascaljLabel)
                                    .addComponent(HectopascaljLabel)
                                    .addComponent(KilopascaljLabel)
                                    .addComponent(MilibarjLabel)
                                    .addComponent(BarjLabel))
                                .addGap(32, 32, 32))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(MetrodeaguajLabel)
                                .addGap(18, 18, 18)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(MetrodeaguajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(PascaljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(KilopascaljTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BarjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(HectopascaljTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(MilibarjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(emjLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(KilopascaljLabel)
                    .addComponent(KilopascaljTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(HectopascaljLabel)
                    .addComponent(HectopascaljTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BarjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BarjLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MilibarjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MilibarjLabel))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PascaljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PascaljLabel))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MetrodeaguajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MetrodeaguajLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 148, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased
        // TODO add your handling code here:
        try {
            Float bar = (float) 0;
            if (jComboBox1.getSelectedItem().equals("Kilopascal")) {
                bar = Float.parseFloat(jTextField2.getText()) / (float) 100;
            } else if (jComboBox1.getSelectedItem().equals("Hectopascal")) {
                bar = Float.parseFloat(jTextField2.getText()) / (float) 1000;
            } else if (jComboBox1.getSelectedItem().equals("Milibar")) {
                bar = Float.parseFloat(jTextField2.getText())/(float) 1000  ;
            } else if (jComboBox1.getSelectedItem().equals("Bar")) {
                bar = Float.parseFloat(jTextField2.getText()) ;
            } else if (jComboBox1.getSelectedItem().equals("Pascal")) {
                bar = Float.parseFloat(jTextField2.getText()) / (float) 100000 ;
            } else if (jComboBox1.getSelectedItem().equals("Metro de água")){
                bar = Float.parseFloat(jTextField2.getText())/(float)10.2;
            }
            Float outrobar = (float) 0;
            outrobar = bar * (float) 100;
            KilopascaljTextField1.setText(outrobar.toString());

            outrobar = bar * (float) 1000;
            HectopascaljTextField1.setText(outrobar.toString());

            BarjTextField.setText(bar.toString());

            outrobar = bar * (float) 1000;
            MilibarjTextField.setText(outrobar.toString());

            outrobar = bar * (float) 100000;
            PascaljTextField.setText(outrobar.toString());

            outrobar = bar * (float) 10.2;
            MetrodeaguajTextField.setText(outrobar.toString());
        } catch (Exception ex) {
            jTextField2.setText("");
            KilopascaljTextField1.setText("");
            HectopascaljTextField1.setText("");
            BarjTextField.setText("");
            MilibarjTextField.setText("");
            PascaljTextField.setText("");
            MetrodeaguajTextField.setText("");
        }

    }//GEN-LAST:event_jTextField2KeyReleased

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
        // TODO add your handling code here:
        jTextField2KeyReleased(null);
}//GEN-LAST:event_jComboBox1ItemStateChanged

    private void BarjTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BarjTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_BarjTextFieldActionPerformed

    private void MilibarjTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MilibarjTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_MilibarjTextFieldActionPerformed

    private void PascaljTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PascaljTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_PascaljTextFieldActionPerformed

    private void MetrodeaguajTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MetrodeaguajTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_MetrodeaguajTextFieldActionPerformed

    private void KilopascaljTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KilopascaljTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_KilopascaljTextField1ActionPerformed

    private void HectopascaljTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HectopascaljTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_HectopascaljTextField1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel BarjLabel;
    private javax.swing.JTextField BarjTextField;
    private javax.swing.JLabel HectopascaljLabel;
    private javax.swing.JTextField HectopascaljTextField1;
    private javax.swing.JLabel KilopascaljLabel;
    private javax.swing.JTextField KilopascaljTextField1;
    private javax.swing.JLabel MetrodeaguajLabel;
    private javax.swing.JTextField MetrodeaguajTextField;
    private javax.swing.JLabel MilibarjLabel;
    private javax.swing.JTextField MilibarjTextField;
    private javax.swing.JLabel PascaljLabel;
    private javax.swing.JTextField PascaljTextField;
    private javax.swing.JLabel emjLabel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

}
